﻿using Dark_Core_Server.Models.Article;
using Dark_Core_Server.Models.User;
using MongoDB.Bson;

namespace Dark_Core_Server.Models.File
{
    /// <summary>
    /// 文件模型帮助类
    /// </summary>
    public static class FileModelHelper
    {
        /// <summary>
        /// 将SimpleFileReferenceRecord转换为FileReferenceDocument
        /// </summary>
        /// <param name="record">记录</param>
        /// <param name="userId">用户ID</param>
        /// <param name="documentId">文档ID</param>
        /// <returns></returns>
        public static FileReferenceDocument ToReferenceDocumentDocument(this SimpleFileReferenceRecord record, ObjectId userId,
            ObjectId documentId)
        {
            return new FileReferenceDocument()
            {
                FileId = documentId,
                UserId = userId,
                VirtualPaths = record.VirtualPaths,
                FileName = record.FileName,
                FileExtenstion = record.FileExtension,
                Level = record.Level??0
            };
        }


        /// <summary>
        /// 转换至文件查询模式
        /// </summary>
        /// <param name="str">模式字符串</param>
        /// <returns></returns>
        public static FileQueryMode ToFileQueryMode(this string str)
        {
            var result = str.ToUpper() switch
            {
                "ALL"=>FileQueryMode.ALL,
                "ID"=>FileQueryMode.ID,
                "MD5"=>FileQueryMode.MD5,
                "COSOBJECTKEY"=>FileQueryMode.COSObjectKey,
                _ => FileQueryMode.ALL
            };
            return result;
        }


        /// <summary>
        /// 转换至文件引用查询模式
        /// </summary>
        /// <param name="str">模式字符串</param>
        /// <returns></returns>
        public static FileReferenceQueryMode ToFileReferenceQueryMode(this string str)
        {

            var result = str.ToUpper() switch
            {
                "ID" => FileReferenceQueryMode.ID,
                "USERID" => FileReferenceQueryMode.UserID,
                "USERIDANDFILENAME" => FileReferenceQueryMode.UserIDAndFileName,
                "USERIDANDFILETYPE" => FileReferenceQueryMode.UserIDAndFileType,
                _ => FileReferenceQueryMode.ID

            };
            return result;

        }

    }
}
